package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCLogin {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入用户名~");
        String userName=scan.nextLine();
        System.out.println("请输入密码~");
        String passWord=scan.nextLine();
        try(Connection connection=DBUtil.getConnextion("tedu")) {
            Statement statement=connection.createStatement();
            String sql="select username,password from userinfo where username='"+userName+"'";
            ResultSet r=statement.executeQuery(sql);
            if (r.next()){
                if (passWord.equals(r.getString("password"))){
                    System.out.println("恭喜你，登录成功！");
                }else{
                    System.out.println("登陆失败，密码错误！");
                }
            }else{
                System.out.println("用户名不存在，请重新输入！");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
